package com.app.basic.controller;


import com.app.basic.dao.entity.SysUser;
import com.app.basic.dao.service.SysUserService;
import com.app.model.dto.PageDTO;
import com.app.utils.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author
 * @since 2023
 */
@RestController
@RequestMapping("/sys/sysUser")
@RequiresRoles("ADMIN")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;


    @PostMapping("page")
    @ApiOperation("用户分页")
    public Result<Page<SysUser>> page(@RequestBody PageDTO pageDTO) {
        return Result.ok(sysUserService.page(pageDTO));
    }


    @GetMapping("getById/{id}")
    @ApiOperation("用户详情")
    public Result<SysUser> getSysUserById(@PathVariable("id") String id) {
        return Result.ok(sysUserService.getSysUserById(id));
    }


    @DeleteMapping("deleteById/{id}")
    @ApiOperation("用户删除")
    public Result<Boolean> deleteSysUserById(@PathVariable("id") String id) {
        return Result.ok(sysUserService.deleteSysUserById(id));
    }

    @PostMapping("add")
    @ApiOperation("用户新增")
    public Result<Boolean> addSysUser(@Valid @RequestBody SysUser obj) {
        return Result.ok(sysUserService.addSysUser(obj)).setShowMsg(true).setMsg("新增成功");
    }


    @PutMapping("updateById")
    @ApiOperation("用户更新")
    public Result<Boolean> updateSysUserById(@Valid @RequestBody SysUser obj) {
        return Result.ok(sysUserService.updateSysUserById(obj)).setMsg("修改成功").setShowMsg(true);
    }


}


